package com.shushan.lockscreen.bean;

import android.util.Log;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.shushan.shushanbao.BabyApplication;
import com.shushan.util.DateUtils;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @ClassName: GameTimeBean
 * @Desciption: 小孩玩应用时间bean
 * @author: yichaohua
 * @date: 2018-06-13
 */
@DatabaseTable(tableName = "game_time_table")
public class GameTimeBean {

    private final static String TAG = "GameTimeBean";

    @DatabaseField(generatedId = true)//自增长的主键
    private int id;
    @DatabaseField
    private int paperId = 0;
    @DatabaseField
    private int childId = 0;
    @DatabaseField
    private String createDate;
    @DatabaseField
    private String usePackName;
    @DatabaseField
    private String useAppLabel;
    @DatabaseField
    private long startTime;
    @DatabaseField
    private long useTime;//毫秒为单位
    @DatabaseField
    private boolean isOver = false;//是否结束标志

    public GameTimeBean() {
        childId = BabyApplication.getInstance().getCurrentChildId();
        createDate = DateUtils.getNowDate("yyyyMMdd");
        startTime = System.currentTimeMillis();
        useTime = 0;
        isOver = false;

        Log.i(TAG,"GameTimeBean() createDate=" + createDate + " startTime=" + startTime);
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getPaperId() {
        return paperId;
    }

    public void setPaperId(int paperId) {
        this.paperId = paperId;
    }

    public int getChildId() {
        return childId;
    }

    public void setChildId(int childId) {
        this.childId = childId;
    }

    public String getUsePackName() {
        return usePackName;
    }

    public void setUsePackName(String usePackName) {
        this.usePackName = usePackName;
    }

    public String getUseAppLabel() {
        return useAppLabel;
    }

    public void setUseAppLabel(String useAppLabel) {
        this.useAppLabel = useAppLabel;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public long getUseTime() {
        return useTime;
    }

    public void setUseTime(long useTime) {
        this.useTime = useTime;
    }

    public boolean isOver() {
        return isOver;
    }

    public void setOver(boolean over) {
        isOver = over;
    }

    public JSONObject toJSONObject() {
        JSONObject jsonObject = new JSONObject();

        try {
            jsonObject.put("id",id);
            jsonObject.put("paperId",paperId);
            jsonObject.put("childId",childId);
            jsonObject.put("createDate",createDate);
            jsonObject.put("usePackName",usePackName);
            jsonObject.put("useAppLabel",useAppLabel);
            jsonObject.put("startTime",startTime);
            jsonObject.put("useTime",useTime/1000);
            jsonObject.put("isOver",isOver);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return jsonObject;

    }
}
